import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import Vant from 'vant'
import 'vant/lib/index.css';
Vue.use(Vant)
import {Toast} from 'vant'
Vue.use(Toast)
import axios from 'axios'
axios.defaults.baseURL='http://litc.pro:9999/'
Vue.prototype.$http=axios
// 开启跨域
axios.defaults.withCredentials = true;
//数据传递方式
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
// Vue.config.productionTip = false
//添加请求拦截器
axios.interceptors.request.use(function(config){
  //在发送请求之前做某事
  let token = localStorage.getItem('token')
  if(token){   //如果有token 则在每个http请求头设置token
    config.headers['Authorization'] = token
  }
  return config;
},function(error){
  //请求错误时做些事
  return Promise.reject(error);
});
//添加响应拦截器
axios.interceptors.response.use(function(response){
     //对响应数据做些事
     return response;

   },function(error){
     console.dir(error)
     //请求错误时做些事
     if(error.response)
     return Promise.reject(error);
   });
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
